import { NavigationGuard } from "vue-router";

// 遍历文件夹下所有的 守卫配置
// BE 开头的为 beforeEach
// BR 开头的为 beforeResolve
// 如果需要确认守卫装置的先后顺序,
// 请在开头后增加 数字标识例如
// BE01xxx
// BE02xxx
// 不是上述开头的文件会被过滤掉
const configContext = require.context(".", false, /\.\/(BE|BR|AE).*.ts$/);
const keys = configContext.keys();

export interface IRouteGuardConfig {
  beforeEach: NavigationGuard[];
  beforeResolve: NavigationGuard[];
}

const configs: IRouteGuardConfig = {
  beforeEach: [],
  beforeResolve: []
};

keys.forEach(key => {
  const s = key.slice(0, 4);
  if (s === "./BR") {
    configs.beforeResolve.push(configContext(key).default);
  } else if (s === "./BE") {
    configs.beforeEach.push(configContext(key).default);
  }
});

export default configs;
